package com.huizhan.web.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Sort.*;
import io.swagger.annotations.*;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;

import com.huizhan.web.view.*;
import com.huizhan.web.dao.*;
import com.huizhan.web.model.*;

@Api(tags = "PersonalProperty",description = "人员属性")
@RestController
public class PersonalPropertyController {
    
    @Autowired
    private PersonalPropertyDao dao;
    
    /**
     * 根据ID获取人信息
     * @param id 人ID
     * @return api结果
     */
    @ApiOperation(value = "根据人员ID获取人员属性集合")
    @RequestMapping(value =  "/api/PersonalProperty/{id}",method = {RequestMethod.GET})
    public ApiResult<List<PersonalProperty>> Get(@PathVariable String id){
        ApiResult<List<PersonalProperty>> result=new ApiResult<List<PersonalProperty>>();
        try
        {
            List<PersonalProperty> list= dao.findByPersonalId(id);
            result.setData(list);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }
    
    /**
     * 修改人信息
     * @param id 人ID
     * @param model 人信息
     * @return api结果
     */
    @ApiOperation(value = "修改人员属性ID")
    @RequestMapping(value =  "/api/PersonalProperty/{id}",method = {RequestMethod.PUT})
    public ApiResult<List<PersonalProperty>> Edit(@PathVariable String id,@RequestBody List<PersonalProperty> model){
        ApiResult<List<PersonalProperty>> result=new ApiResult<List<PersonalProperty>>();
        try
        {
            dao.deleteByPersonalId(id);

            for (PersonalProperty personalProperty : model) {
                personalProperty.setPersonalId(id);
                dao.save(personalProperty);
            }
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

}